const db = require("./mysql");

const array=[];

const findList = () => {
    return new Promise((resolve, reject) => {
        let sql = `select address from app_wallet`;
        // console.info("find buy list:",sql);
        db.query(sql, (error, results,fields) => {
            if (error) {
                reject(error);
            } else {
                resolve(results);
            }
       })
  }
)}

const init = async () => {
    const list=await findList();
    list.forEach(item=>{
        if(array.includes(item.address)){
            return;
        }
        array.push(item.address);
    })
}



const includes = async (address) => {
    if(!address){
        return false;
    }
    if(array.length==0){
        await init();
    }
    return array.includes(address);
}


// setInterval(async function(){
//     log.info("wallet sync task ...");
//     await init();
//     log.info(`wallet size: ${array.length}`);
// },1000);

module.exports = {
	findList,
    includes
}